#!/bin/bash

DATA_FILE="save.txt"
WGET="wget"
TARGET_PKG_DIR="./pkgs"
#awk '{print $3 }' $DATA_FILE |  awk 'BEGIN { FS="
#cat $DATA_FILE | cut -d"/" -f 1
cat $DATA_FILE | while read dl_addr; do
    repo_db_file=$(awk 'BEGIN { FS="/" } {print $NF}' <<< $dl_addr)
    echo "$repo_db_file ==>> $dl_addr"
    TARGET_FILE=${TARGET_PKG_DIR}/${repo_db_file} 
    if [ -e ${TARGET_FILE} ] ; then
        echo "${TARGET_FILE} is exist!!! rm ....."
        rm -f ${TARGET_FILE}
    else
        echo "${TARGET_FILE} not found!!!"
    fi
    $WGET $dl_addr -O ${TARGET_FILE}
    dl_stat=$?
    if [ $dl_stat -eq 0 ] ; then
        echo "Download $dl_addr Success!"
    else
        echo "Download $dl_addr faile!!!!!"
    fi
done
